import urllib2, os
from sys import exit

proxy_vars = {'host': '192.168.0.1',
			'port': '3128',
			'user': '',
			'password': '',
			}

url_test='http://www.lacordilleraandina.com.ar/sin.flash/main.html'

def use_proxy (url_test, proxy_vars):
	password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
	password_mgr.add_password (None, proxy_vars['host'],proxy_vars['user'],\
		proxy_vars['password'])
	auth_handler = urllib2.ProxyBasicAuthHandler(password_mgr)
	proxy_url = 'http://%(host)s:%(port)s/' % proxy_vars
	proxy_handler = urllib2.ProxyHandler( {'http': proxy_url} )
	os.environ['http_proxy'] = 'http://%(user)s:%(password)s@%(host)s:%(port)s/' % proxy_vars
			 
	opener = urllib2.build_opener(proxy_handler, auth_handler)
	urllib2.install_opener(opener)
	try:
		page = urllib2.urlopen(url_test)
		print page.info()
		print page.read()
	except urllib2.HTTPError, msg_err:
		print "#### HTTPError.info()"
		print msg_err.info()
		print "#### HTTPError.geturl()"
		print msg_err.geturl()		
		
if __name__ == '__main__':
	use_proxy(url_test, proxy_vars)
